This notebook contains code to process raw data provided for CEGE0042 final assignment. It covers:
Project set up
Area selection (Islington)
Data sub-selection for further analysis
#Packages
library(sf)
Linking to GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2
library(sp)
library(tmap)
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
replacing previous import ‘sf::st_make_valid’ by ‘lwgeom::st_make_valid’ when loading ‘tmap’
#Working directory definition
#getwd()
#Load data
cege_data <- "./0_source_data/UJTWorkSpace.RData"
load(cege_data)
#In UJT there are 256 link ids with data
all_UJT_links <- colnames(UJT)
length(all_UJT_links)
[1] 256
#In our shape file, there are 1402 link ids
length(LCAPShp$LCAP_ID)
[1] 1402
#Flag which links in shape file we have data for
LCAPShp$HaveDataFlag <- 0
counter <- 0
for (master_link_value in LCAPShp$LCAP_ID) {
counter <- counter + 1
if (master_link_value %in% all_UJT_links) {
LCAPShp$HaveDataFlag[counter] <- 1
}
else{
LCAPShp$HaveDataFlag[counter] <- 0
}
}
#Check that sum is equal to all links we have data for
sum(LCAPShp$HaveDataFlag)
[1] 256
# Link shp file to to sf object
LCAPShp_sf <- st_as_sf(LCAPShp)
# Visualise field to show links with speed data
#plot(LCAPShp_sf["HaveDataFlag"])
# Load reference shape file for London Borough
# read in polygon shp and set crs to match
LondonBor <- st_read('./1_shape_files/shapefiles/London_Borough_Excluding_MHW.shp') %>%
st_transform(LondonBor, crs = st_crs(LCAPShp_sf))
Reading layer `London_Borough_Excluding_MHW' from data source `/cloud/project/1_shape_files/shapefiles/London_Borough_Excluding_MHW.shp' using driver `ESRI Shapefile'
Simple feature collection with 33 features and 7 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 503568.2 ymin: 155850.8 xmax: 561957.5 ymax: 200933.9
proj4string: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601272 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs
# for interactive viewing
tmap_mode("view")
tmap mode set to interactive viewing
# layer the boroughs, all links, and selected links
tm_shape(LondonBor)+
tm_polygons(col='white')+
tm_shape(LCAPShp_sf)+
tm_lines(col='lightgreen')+
tm_shape(LCAPShp_sf["LCAP_ID"])+
tm_lines(col = "LCAP_ID")